<template>
	<view class="follow">
		<!-- 导航切换 -->
		<view class="follow-tab">
			<view class="follow-tab_box">
				<view class="follow-tab_item" :class="{active : activeIndex ===0}" @click="tab(0)">文章</view>
				<view class="follow-tab_item" :class="{active : activeIndex ===1}" @click="tab(1)">作者</view>
			</view>
		</view>
		<view class="follow-list">
			<swiper class="follow-list__swiper" :current="activeIndex" @change="change">
				
				<swiper-item>
 					<!-- <view class="swiper-item">文章</view> -->
					<list-scroll>
						<uni-load-more v-if="list.length === 0 && !articleShow" iconType="snow" :status="loading"></uni-load-more>
						<view class="no-data" v-if="articleShow">没有收藏文章</view>
						<list-card v-for="item in list" :key="item._id"  :item="item"  types="follow"></list-card>
					</list-scroll>
				</swiper-item>
				
				<swiper-item>
					<!-- <list-card v-for="item in list" :key="item._id"  :item="item"></list-card> -->
					<list-scroll>
						<list-author v-for="item in authorList" :key="item._id" :item="item" ></list-author>
						<view class="no-data" v-if="followShow">没有关注作者</view>
					</list-scroll>
				</swiper-item>
				
			</swiper>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeIndex:0,
				list:[],
				authorList:[],
				loading:"loading",
				articleShow:false,
				followShow:false
			}
		},
		onLoad(){
			//自定义事件，$on只能在打开的页面触发e
			uni.$on("update_article",(e)=>{
				console.log('关注页面事件')
				console.log(e)
				this.getFollow()
			})
			uni.$on("update_author",()=>{
				this.getAuthor()
			})
			this.getFollow()
			this.getAuthor()
		},
		methods: {
			change(e){
				this.activeIndex = e.detail.current
			},
			tab(index){
				console.log(index)
				this.activeIndex = index
			},
			getFollow(){
				this.$api.get_follow().then(res =>{
					console.log('70-:',res) 
					const {data} =res
					this.list = data
					
					this.articleShow = this.list.length === 0?true:false
				})
			},
			getAuthor(){
				this.$api.get_author().then(res=>{
					console.log(res)
					const {data} = res
					this.authorList = data
					// console.log(this.authorList)
					console.log("86+this.authorList:", this.authorList.length)
					console.log("87+this.authorList:", this.authorList)
					
					
					this.followShow = this.authorList.length === 0?true : false
				})
			}
		}
	}
</script>

<style lang="scss">
page{
	height: 100%;
	display: flex;
}
.follow{
	height:100%;
	display:flex;
	flex-direction:column;
	box-sizing: border-box;
	// border:1px solid red;
	flex:1;
	
	.follow-tab{
		height: 30px;
		padding:10px 20px;
		border-bottom:1px #f5f5f5 solid;
		
		.follow-tab_box{
			display:flex;
		    width:100%;
			height:100%;
			border-radius: 5px;
			border:1px solid $mk-base-color;
			
			.follow-tab_item{
				width:100%;
				display: flex;
				justify-content: center;//水平居中
				align-items: center;//垂直居中
				color:#666;
				font-size: 14px;
				
				&:first-child{
					border-right: 1px $mk-base-color solid;
				}
				&.active{
					color:$mk-base-color;
				}
			}
		}
	}
	.follow-list{
		flex:1;
		
		.follow-list__swiper{
			height:100%;
			
			.swiper-item{
				height:100%;
			}
			
		}
	}
}
.no-data{
	padding:50px;
	font-size: 14px;
	color:#999;
	text-align: center;
}
</style>
